package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.ManageService;
import io.minio.*;
import io.minio.errors.MinioException;
import io.swagger.annotations.Api;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/7/8 10:49
 * @Version 1.0
 */
@Api(tags = "文件上传")
@RestController
@RequestMapping("/admin/product")
public class FileUploadController {

    //    minio:
    //    endpointUrl: http://192.168.200.130:9000
    //    accessKey: admin
    //    secreKey: admin123456
    //    bucketName: atguigus

    @Autowired
    private ManageService manageService;


    //  文件上传：使用springmvc 封装好的上传类
    @PostMapping("/fileUpload")
    public Result fileUpload(MultipartFile file){
        //  获取到文件上传路径。
        String url = manageService.fileUpload(file);
        //  返回路径
        return Result.ok(url);
    }
}
